<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/GroupSummary.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript">
        	var piMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.productidentification');
			var ppMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.productprice');
			var orderMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.order');
			var referenceMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.reference');
			var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
			var msMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.measurespecification');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
			var ctYesno = new i18nMessage('../../servlet/CodeTableServlet?name=CtYesno');
			
			var ctSeasonNumberXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtSeasonNumber');
			var ctVersionXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtVersion');
			var ctProductFamilyXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtProductFamily');
			var ctDesignTypeXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtDesignType');
			
			var store;
            var grid;
			
			var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/ProductPriceServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
				
				store = new Ext.data.Store({
                    url: '../../servlet/ProductPriceServlet?action=4',
                    
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [
                    'index','id', 'piId', {
					 	name: 'productIdentification.ctProductFamily',
					 	mapping: 'ctProductFamily'
					 }, {
					 	name: 'productIdentification.ctDesignType',
					 	mapping: 'ctDesignType'
					 },{
					 	name: 'productIdentification.ctSeasonNumber',
					 	mapping: 'ctSeasonNumber'
					 },{
					 	name: 'productIdentification.orderNumber',
					 	mapping: 'orderNumber'
					 }, {
					 	name: 'productIdentification.reference',
					 	mapping: 'reference'
					 },'createDate',{
					 	name: 'productIdentification.patronageNumer',
					 	mapping: 'patronageNumer'
					 },{
					 	name: 'productIdentification.ctVersion',
					 	mapping: 'ctVersion'
					 }, 
					 'front', 'style',
					 'back', 'sleeves', 'bottomThrum', 
					 'sleevesThrum', 'necklineThrum', 'needle', 
					 'weight', 'comment', 'photoName', 'frontPhotoName','backPhotoName','otherPhotoName',
					 'chartName', 'modifyDate', 'orderNumber',
					 'isSimilary', 'isNewfashioned', 'isDifficulty', 
					 'dhlNumber', {name: 'productIdentification.biFranceCustomer.name', mapping: 'customerName'},
					 {name: 'productIdentification.biFranceCustomer.department', mapping: 'customerDepartment'},  
					 {
					 	name: 'productIdentification.isSimilary',
					 	mapping: 'isSimilary'
					 },{
					 	name: 'productIdentification.isNewfashioned',
					 	mapping: 'isNewfashioned'
					 },{
					 	name: 'productIdentification.isDifficulty',
					 	mapping: 'isDifficulty'
					 },{
					 	name: 'productIdentification.isNewfashioned',
					 	mapping: 'isNewfashioned'
					 },{
					 	name: 'productIdentification.ctStature',
					 	mapping: 'ctStature'
					 }, 'unitPrice', 'realPrice', 'totalPrice', 'carriage', 'fob', 'cfi']),
                    
                    remoteSort: true
                });
				
				store.setDefaultSort('id', 'desc');
				
				var filters = new Ext.grid.GridFilters({
					  filters:[
					    {type: 'string',  dataIndex: 'productIdentification.biReference.reference'},
						{type: 'string',  dataIndex: 'productIdentification.seasonNumber'},
						{type: 'string',  dataIndex: 'productIdentification.orderNumber'},
						{type: 'string',  dataIndex: 'productIdentification.biFranceCustomer.name'},
						{
							type: 'list',  
							dataIndex: 'productIdentification.isSimilary', 
							options: ctYesno.getCtArray()
						},{
							type: 'list',  
							dataIndex: 'productIdentification.isNewfashioned', 
							options: ctYesno.getCtArray()
						},{
							type: 'list',  
							dataIndex: 'productIdentification.isNewfashioned', 
							options: ctYesno.getCtArray()
						}
				]});
				
				var expander = new Ext.grid.RowExpander({
			        tpl : new Ext.Template(
						'<p><b>' + piMessage.get('ui.productidentification.style') + ':</b> {style}</p><br/> ',
						'<p><b>' + piMessage.get('ui.productidentification.ordernumber') + ':</b> {orderNumber} &nbsp;&nbsp;&nbsp;&nbsp;<b>' + piMessage.get('ui.productidentification.dhl') + ':</b> {dhlNumber} &nbsp;&nbsp;&nbsp;&nbsp;</p><br/>',
			            '<p><b>' + referenceMessage.get('ui.reference.front') + ':</b> {front} &nbsp;&nbsp;&nbsp;&nbsp; <b>' + referenceMessage.get('ui.reference.back') + ':</b> {back}&nbsp;&nbsp;&nbsp;&nbsp;',
						'<b>' + referenceMessage.get('ui.reference.sleeves') + ':</b> {sleeves} &nbsp;&nbsp;&nbsp;&nbsp; <b>' + referenceMessage.get('ui.reference.bottomthrum') + ':</b> {bottomThrum}&nbsp;&nbsp;&nbsp;&nbsp;',
						'<b>' + referenceMessage.get('ui.reference.sleevesthrum') + ':</b> {sleevesThrum} &nbsp;&nbsp;&nbsp;&nbsp; <b>' + referenceMessage.get('ui.reference.necklinethrum') + ':</b> {necklineThrum}&nbsp;&nbsp;&nbsp;&nbsp;</p><br/>',
			            '<p><b>' + referenceMessage.get('ui.reference.needle') + ':</b> {needle} &nbsp;&nbsp;&nbsp;&nbsp; <b>' + referenceMessage.get('ui.reference.machinetype') + ':</b> {ctMachineType}&nbsp;&nbsp;&nbsp;&nbsp;',
						'<b>' + referenceMessage.get('ui.reference.weight') + ':</b> {weight} &nbsp;&nbsp;&nbsp;&nbsp; <b>',// + piMessage.get('ui.productidentification.yarnnumber') + ':</b> {yarnNumber}&nbsp;&nbsp;&nbsp;&nbsp;',
						'</p><br/>',
						'<p><img src="../../_temp/{chartName}" width="150px"/> &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_temp/{photoName}" width="150px"/>',
						//&nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_temp/{frontPhotoName}" width="150px"/>&nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_temp/{backPhotoName}" width="150px"/>&nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_temp/{otherPhotoName}" width="150px"/></p><br/>',
						'<br/><br/><p><b>' + piMessage.get('ui.productidentification.comment') + ':</b> {comment}</p><br/>'
			        )
			    });
				
				grid = new Ext.grid.GridPanel({
                    title: ppMessage.get('ui.productprice.listtitle'),
                    store: store,
					stripeRows: true,
					plugins: [expander, filters],
                    height: 560,
                    columns: [expander,{
                        header: message.get('message.list.id'),
                        width: 50,
                        dataIndex: 'index',
                        sortable: false
                    },{
                        header: message.get('message.edit.productfamily'),
                        dataIndex: 'productIdentification.ctProductFamily',
                        sortable: true
                    },{
                        header: piMessage.get('ui.productidentification.designtype'),
                        dataIndex: 'productIdentification.ctDesignType',
                        sortable: true
                    },{
                        header: referenceMessage.get('ui.reference.reference'),
                        dataIndex: 'productIdentification.reference',
                        sortable: true
                    },{
                        header: piMessage.get('ui.productidentification.seasonnumber'),
                        dataIndex: 'productIdentification.ctSeasonNumber',
                        sortable: true
                    },{
                        header: piMessage.get('ui.productidentification.patronagenumer'),
                        dataIndex: 'productIdentification.patronageNumer',
                        sortable: true
                    },{
                        header: piMessage.get('ui.productidentification.chartversion'),
                        dataIndex: 'productIdentification.ctVersion',
                        sortable: true
                    },{
                        header: message.get('message.edit.customername'),
                        dataIndex: 'productIdentification.biFranceCustomer.name',
                        sortable: true
                    },{
                        header: fcMessage.get('ui.francecustomer.department'),
                        dataIndex: 'productIdentification.biFranceCustomer.department',
                        sortable: true
                    },{
                        header: msMessage.get('ui.measurespecification.stature'),
                        dataIndex: 'productIdentification.ctStature',
                        sortable: true,
						renderer: renderType
                    },{
                        header: piMessage.get('ui.productidentification.isnewfashioned'),
                        dataIndex: 'productIdentification.isNewfashioned',
                        sortable: true,
						renderer: renderIsYesno
                    },{
                        header: piMessage.get('ui.productidentification.issimilary'),
                        dataIndex: 'productIdentification.isSimilary',
                        sortable: true,
						renderer: renderIsYesno
                    },{
                        header: piMessage.get('ui.productidentification.isdifficulty'),
                        dataIndex: 'productIdentification.isDifficulty',
                        sortable: true,
						renderer: renderIsYesno
                    },{
						header: ppMessage.get('ui.productprice.unitprice'),
						dataIndex: 'unitPrice',
						align: 'right',
						sortable: true,
						renderer: eurMoney
					},{
						header: ppMessage.get('ui.productprice.totalprice'),
						dataIndex: 'totalPrice',
						align: 'right',
						sortable: true,
						renderer: eurMoney
					},{
						header: ppMessage.get('ui.productprice.carriage'),
						dataIndex: 'carriage',
						align: 'right',
						sortable: true,
						renderer: eurMoney
					},{
						header: ppMessage.get('ui.productprice.fob'),
						dataIndex: 'fob',
						align: 'right',
						sortable: true,
						renderer: eurMoney
					},{
						header: ppMessage.get('ui.productprice.cfi'),
						dataIndex: 'cfi',
						align: 'right',
						sortable: true,
						renderer: eurMoney
					},{
						header: ppMessage.get('ui.productprice.quote'),
						dataIndex: 'id',
						sortable: false,
						renderer: renderPrice
					}],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'productPriceGrid',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
				
				var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });
				
				var orderWin;
				
				grid.on('rowdblclick', function(grid, rowIndex, e){
                    if (!orderWin) {
                        orderWin = new Ext.Window({
                            title: message.get('message.window.detail'),
                            layout: 'fit',
                            width: 600,
                            height: 400,
                            closeAction: 'hide',
                            plain: true,
                            items: [{
                                id: 'detailPanel',
                                region: 'center',
                                bodyStyle: {
                                    background: '#ffffff',
                                    padding: '7px'
                                },
                                html: message.get('message.window.empty')
                            }]
                        });
                    }
                    
                    orderWin.show(this);
                    var itemTplMarkup = [
						'<div id="orderList"></div>'
					];
                    var itemTpl = new Ext.Template(itemTplMarkup);
                    var detailPanel = Ext.getCmp('detailPanel');
                    itemTpl.overwrite(detailPanel.body, grid.getStore().getAt(rowIndex).data);
					
					var listStore = new Ext.data.GroupingStore({
	                   url: '../../servlet/OrderServlet?action=5&id=' + grid.getStore().getAt(rowIndex).data.piId,
	                   reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
	                    }, ['index', 'id', 'pantoneNumber', 'colorNumber', 'realColor', 
							{
								name: 'amountS',
								type: 'int'
							}, {
								name: 'amountM',
								type: 'int'
							}, {
								name: 'amountL',
								type: 'int'
							}, {
								name: 'amountXl',
								type: 'int'
							}, {
								name:'amountXxl',
								type: 'int'
							}, {
								name:'amountXxxl',
								type: 'int'
							}, {
								name:'total',
								type: 'int'
							}, 
							'colorA', 'pantoneNumberA', 'realColorA', 'percentageA', 
							'colorB', 'pantoneNumberB', 'realColorB', 'percentageB', 
							'colorC', 'pantoneNumberC', 'realColorC', 'percentageC', 
							'colorD', 'pantoneNumberD', 'realColorD', 'percentageD', 
							'colorE', 'pantoneNumberE', 'realColorE', 'percentageE', 
							'colorF', 'pantoneNumberF', 'realColorF', 'percentageF', 
							'colorG', 'pantoneNumberG', 'realColorG', 'percentageG', 
							'colorH', 'pantoneNumberH', 'realColorH', 'percentageH']),
	                    
	                   	groupField: 'index',
	                    sortInfo: {
	                        field: 'index',
	                        direction: "ASC"
	                    }
	                });
					
					var summary = new Ext.grid.GroupSummary();
					var listGrid = new Ext.grid.GridPanel({
	                    title: orderMessage.get('ui.order.listtitle'),
	                    store: listStore,
	                    stripeRows: true,
	                    height: 340,
	                    columns: [{
	                        header: message.get('message.list.id'),
	                        width: 50,
	                        dataIndex: 'index',
	                        sortable: false
	                    },{
	                        id: 'colorNumber',
	                        header: orderMessage.get('ui.order.color'),
	                        dataIndex: 'colorNumber',
							groupable: false,
							summaryRenderer: function(v, params, data){
			                    return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + message.get('message.list.total');
			                }
	                    },{
	                        header: 'S',
	                        dataIndex: 'amountS',
	                        sortable: false,
							align: 'right',
							groupable: false,
							summaryType:'sum'
	                    },{
	                        header: 'M',
	                        dataIndex: 'amountM',
	                        sortable: false,
							align: 'right',
							groupable: false,
							summaryType:'sum'
	                    },{
	                        header: 'L',
	                        dataIndex: 'amountL',
	                        sortable: false,
							align: 'right',
							groupable: false,
							summaryType:'sum'
	                    },{
	                        header: 'XL',
	                        dataIndex: 'amountXl',
	                        sortable: false,
							align: 'right',
							groupable: false,
							summaryType:'sum'
	                    },{
	                        header: 'XXL',
	                        dataIndex: 'amountXxl',
	                        sortable: false,
							align: 'right',
							groupable: false,
							summaryType:'sum'
	                    },{
	                        header: 'XXXL',
							align: 'right',
	                        dataIndex: 'amountXxxl',
	                        sortable: false,
							groupable: false,
							summaryType:'sum'
	                    },{
	                        header: message.get('message.list.total'),
							id: 'total',
	                        dataIndex: 'total',
							align: 'right',
							groupable: false,
	                        sortable: false,
							summaryType:'sum'
	                    }],
	                    view: new Ext.grid.GroupingView({
	                        forceFit: true,
							hideGroupedColumn: true,
							enableNoGroups:false,
	                        groupTextTpl: '&nbsp;'
	                    }),
	                    loadMask: true,
	                    plugins: [summary],
	                    renderTo: 'orderList'
	                });
                
					listStore.load();
					
					
	            });
				
			});
			
			var renderType = function(value, p, record){
				if(value == ''){
					return String.format('<img src="../../images/icons/tag_blue_add.png" title="' + piMessage.get('ui.productidentification.tag') + '" /><img width="10" src="../../images/icons/cross.png">');
				}else{
					return String.format(value);
				}
			}
			
			function renderIsYesno(value, p, record){
				if(value == '')
					return String.format('<img src="../../images/icons/tag_blue_add.png" title="' + piMessage.get('ui.productidentification.tag') + '" /><img width="10" src="../../images/icons/cross.png">');
				else if(value == '02')
					return String.format('<img ext:qtip="{0}" src="../../images/icons/cross.png" />', record.data.comment8);
				else
					return String.format('<img ext:qtip="{0}" src="../../images/icons/tick.png"/>', record.data.comment8);
            }
			
			function renderPrice(value, p, record){
				return String.format('<a href="product_price_edit.html?id={0}&piId={1}&startPage={2}" target="_self"><img src="../../images/icons/money_euro.png" title="' + ppMessage.get('ui.productprice.quote') + '" /></a>', record.id, record.data.piId, Math.floor((record.data.index - 1) / 20) + 1);
			}			
		</script>
</head>
<body>
	<div id="productPriceGrid"></div>
</body>
</html>